home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / gofer221.zip / CH00 < prev    next >
Text File  |  1991-11-20  |  8KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.          __________   __________   __________   __________   ________
  8.         /  _______/  /  ____   /  /  _______/  /  _______/  /  ____  \
  9.        /  / _____   /  /   /  /  /  /______   /  /______   /  /___/  /
  10.       /  / /_   /  /  /   /  /  /  _______/  /  _______/  /  __   __/
  11.      /  /___/  /  /  /___/  /  /  /         /  /______   /  /  \  \ 
  12.     /_________/  /_________/  /__/         /_________/  /__/    \__\
  13.  
  14.     Functional programming environment, Version 2.20
  15.  
  16.     Copyright Mark P Jones 1991.
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.             A N   I N T R O D U C T I O N   T O   G O F E R
  24.  
  25.  
  26.      draft version only --- please report any errors, suggestions for
  27.        improvements, extensions (or deletions!) to mpj@prg.ox.ac.uk
  28.  
  29.  
  30.  
  31.  
  32.  
  33.    --------------------------------------------------------------------
  34.    Permission to use, copy, modify, and distribute  this  software  and
  35.    its documentation for any personal or educational use without fee is
  36.    hereby granted, provided that:
  37.  
  38.     a) This copyright notice  is  retained  in  both  source  code  and
  39.        supporting documentation.
  40.  
  41.     b) Modified versions  of  this  software  cannot  be  redistributed
  42.        unless  accompanied  by  a  complete  history   (date,   author,
  43.        description) of modifications made; the  intention  here  is  to
  44.        give appropriate credit to those involved, whilst simultaneously
  45.        ensuring that any recipient can  determine  the  origin  of  the
  46.        software.
  47.  
  48.     c) These same conditions will  also  be  applied  to  any  software
  49.        system derived either in full or in part from Gofer.
  50.  
  51.    The name "Gofer" is not a trademark, registered  or  otherwise,  and
  52.    you are free to mention this name in published material, public  and
  53.    private correspondence, or other documents  without  restriction  or
  54.    obligation.
  55.  
  56.    Gofer is provided "as is" without express or implied warranty.
  57.    --------------------------------------------------------------------
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. Introduction to Gofer                                                           
  70.  
  71.  
  72.                       T A B L E   O F   C O N T E N T S 
  73.  
  74.  
  75.     1. INTRODUCTION. . . . . . . . . . . . . . . . . . . . . . . . . .  1
  76.  
  77.     2. BACKGROUND AND ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . .  2
  78.  
  79.     3. STARTING GOFER. . . . . . . . . . . . . . . . . . . . . . . . .  4
  80.  
  81.     4. USING GOFER - A BASIC INTRODUCTION. . . . . . . . . . . . . . .  5
  82.  
  83.     5. STANDARD AND USER-DEFINED FUNCTIONS . . . . . . . . . . . . . .  6
  84.  
  85.     6. FUNCTION NAMES - IDENTIFIERS AND OPERATORS. . . . . . . . . . .  8
  86.  
  87.     7. BUILT-IN TYPES. . . . . . . . . . . . . . . . . . . . . . . . . 12
  88.     7.1  Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 12
  89.     7.2  Booleans. . . . . . . . . . . . . . . . . . . . . . . . . . . 13
  90.     7.3  Integers. . . . . . . . . . . . . . . . . . . . . . . . . . . 13
  91.     7.4  Floating point numbers. . . . . . . . . . . . . . . . . . . . 14
  92.     7.5  Characters. . . . . . . . . . . . . . . . . . . . . . . . . . 14
  93.     7.6  Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
  94.     7.7  Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
  95.     7.8  Tuples and the unit type. . . . . . . . . . . . . . . . . . . 18
  96.  
  97.     8. ERRORS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
  98.     8.1  Errors detected on input. . . . . . . . . . . . . . . . . . . 19
  99.     8.2  Errors during evaluation. . . . . . . . . . . . . . . . . . . 19
  100.  
  101.     9. MORE ABOUT VALUE DECLARATIONS . . . . . . . . . . . . . . . . . 21
  102.     9.1  Simple pattern matching . . . . . . . . . . . . . . . . . . . 21
  103.     9.2  Guarded equations . . . . . . . . . . . . . . . . . . . . . . 23
  104.     9.3  Local definitions . . . . . . . . . . . . . . . . . . . . . . 24
  105.     9.4  Recursion with integers . . . . . . . . . . . . . . . . . . . 24
  106.     9.5  Recursion with lists. . . . . . . . . . . . . . . . . . . . . 26
  107.     9.6  Lazy evaluation . . . . . . . . . . . . . . . . . . . . . . . 27
  108.     9.7  Infinite data structures. . . . . . . . . . . . . . . . . . . 29
  109.     9.8  Polymorphism. . . . . . . . . . . . . . . . . . . . . . . . . 30
  110.     9.9  Higher-order functions. . . . . . . . . . . . . . . . . . . . 31
  111.     9.10 Variable declarations . . . . . . . . . . . . . . . . . . . . 32
  112.     9.11 Pattern bindings and irrefutable patterns . . . . . . . . . . 33
  113.     9.12 Type declarations . . . . . . . . . . . . . . . . . . . . . . 35
  114.  
  115.     10. INCREASING YOUR POWER OF EXPRESSION. . . . . . . . . . . . . . 37
  116.     10.1 Arithmetic sequences. . . . . . . . . . . . . . . . . . . . . 37
  117.     10.2 List comprehensions . . . . . . . . . . . . . . . . . . . . . 38
  118.     10.3 Lambda expressions. . . . . . . . . . . . . . . . . . . . . . 41
  119.     10.4 Case expressions. . . . . . . . . . . . . . . . . . . . . . . 42
  120.     10.5 Operator sections . . . . . . . . . . . . . . . . . . . . . . 43
  121.     10.6 Explicitly typed expressions. . . . . . . . . . . . . . . . . 44
  122.  
  123.     11. USER-DEFINED DATATYPES AND TYPE SYNONYMS . . . . . . . . . . . 46
  124.     11.1 Datatype definitions. . . . . . . . . . . . . . . . . . . . . 46
  125.     11.2 Type synonyms . . . . . . . . . . . . . . . . . . . . . . . . 47
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. Introduction to Gofer                                                           
  136.  
  137.  
  138.     12. DIALOGUES: INPUT AND OUTPUT. . . . . . . . . . . . . . . . . . 49
  139.     12.1 Basic description . . . . . . . . . . . . . . . . . . . . . . 49
  140.     12.2 Continuation style I/O. . . . . . . . . . . . . . . . . . . . 52
  141.     12.3 Interactive programs. . . . . . . . . . . . . . . . . . . . . 55
  142.  
  143.     13. LAYOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  144.     13.1 Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  145.     13.2 The layout rule . . . . . . . . . . . . . . . . . . . . . . . 57
  146.  
  147.     14. OVERLOADING IN GOFER . . . . . . . . . . . . . . . . . . . . . 61
  148.     14.1 Type classes and predicates . . . . . . . . . . . . . . . . . 61
  149.     14.2 The type class Eq . . . . . . . . . . . . . . . . . . . . . . 62
  150.     14.2.1 Implicit overloading. . . . . . . . . . . . . . . . . . . . 62
  151.     14.2.2 Instances of class Eq . . . . . . . . . . . . . . . . . . . 63
  152.     14.2.3 Testing equality of represented values. . . . . . . . . . . 65
  153.     14.2.4 Instance declarations without members . . . . . . . . . . . 66
  154.     14.2.5 Equality on function types. . . . . . . . . . . . . . . . . 66
  155.     14.2.6 Non-overlapping instances . . . . . . . . . . . . . . . . . 67
  156.     14.3 Dictionaries. . . . . . . . . . . . . . . . . . . . . . . . . 68
  157.     14.3.1 Superclasses. . . . . . . . . . . . . . . . . . . . . . . . 71
  158.     14.3.2 Combining classes . . . . . . . . . . . . . . . . . . . . . 73
  159.     14.3.3 Simplified contexts . . . . . . . . . . . . . . . . . . . . 74
  160.     14.4 Other issues. . . . . . . . . . . . . . . . . . . . . . . . . 76
  161.     14.4.1 Unresolved overloading. . . . . . . . . . . . . . . . . . . 76
  162.     14.4.2 `Recursive' dictionaries. . . . . . . . . . . . . . . . . . 79
  163.     14.4.3 Classes with multiple parameters. . . . . . . . . . . . . . 81
  164.     14.4.4 Overloading and numeric values. . . . . . . . . . . . . . . 83
  165.     14.4.5 Constants in dictionaries . . . . . . . . . . . . . . . . . 86
  166.     14.4.6 The monomorphism restriction. . . . . . . . . . . . . . . . 88
  167.  
  168.     APPENDIX A: SUMMARY OF GRAMMAR . . . . . . . . . . . . . . . . . . 93
  169.  
  170.     APPENDIX B: CONTENTS OF STANDARD PRELUDE . . . . . . . . . . . . . 97
  171.  
  172.     APPENDIX C: RELATIONSHIP WITH HASKELL 1.1. . . . . . . . . . . . .111
  173.  
  174.     APPENDIX D: USING GOFER WITH BIRD+WADLER . . . . . . . . . . . . .115
  175.  
  176.     APPENDIX E: PRIMITIVES . . . . . . . . . . . . . . . . . . . . . .117
  177.  
  178.     APPENDIX F: INTERPRETER COMMAND SUMMARY. . . . . . . . . . . . . .119
  179.  
  180.     APPENDIX G: BIBLIOGRAPHY . . . . . . . . . . . . . . . . . . . . .121
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.